package com.atguigu.controller;


import com.atguigu.entity.*;
import com.atguigu.result.RetVal;
import com.atguigu.service.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author hachimen
 * @since 2021-08-24
 */
@RestController
@RequestMapping("product")
public class ProductSpuController {
    @Autowired
    private ProductSpuService productSpuService;
    @Autowired
    private BaseSalePropertyService baseSalePropertyService;


    //SPU分页查询
    @GetMapping("queryProductSpuByPage/{page}/{limit}/{baseCategory3Id}")
    public RetVal queryProductSpuByPage(@PathVariable Long page,
                                        @PathVariable Long limit,
                                        @PathVariable Long baseCategory3Id){
        Page<ProductSpu> productSpuPage = new Page<>(page, limit);
        QueryWrapper<ProductSpu> wrapper = new QueryWrapper<>();
        wrapper.eq("category3_id",baseCategory3Id);
        wrapper.orderByDesc("id");
        productSpuService.page(productSpuPage,wrapper);
        return RetVal.ok(productSpuPage);
    }

    //SPU模子属性全查询
    @GetMapping("queryAllSaleProperty")
    public RetVal queryAllSaleProperty(){
        List<BaseSaleProperty> list = baseSalePropertyService.list(null);
        return RetVal.ok(list);
    }

    //SPU新增
    @PostMapping("saveProductSpu")
    public RetVal saveProductSpu(@RequestBody ProductSpu productSpu){
        productSpuService.saveProductSpu(productSpu);
        return RetVal.ok();
    }
}

